package com.yznote.cloudesk.logs;

import com.alibaba.fastjson.JSON;
import com.yznote.cloudesk.common.pojo.Message;
import com.yznote.cloudesk.common.pojo.YLogs;
import com.yznote.cloudesk.logs.mapper.YLogsMapper;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        topic = "logsToMysql",                      // 1.topic：消息的发送者使用同一个topic
        consumerGroup = "logs-group",               // 2.group：不用和生产者group相同 ( 在RocketMQ中消费者和发送者组没有关系 )
        selectorExpression = "*",                   // 3.tag：设置为 * 时，表示全部。
        messageModel = MessageModel.CLUSTERING    // 4.消费模式：默认 CLUSTERING （ CLUSTERING：负载均衡 ）（ BROADCASTING：广播机制 ）
)
public class LogsConsumer implements RocketMQListener {
    @Autowired
    YLogsMapper yLogsMapper;

    @Override
    public void onMessage(Object o) {
        YLogs yLogs = JSON.parseObject((String)o,YLogs.class);
        yLogsMapper.insertLogs(yLogs);
    }
}
